﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using RecruitmentSystem.Business;
using RecruitmentSystem.Common;

public partial class StudentManagement_EditBasicInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindStudentBasicInfo();
        }
    }

    private void BindStudentBasicInfo()
    {
        AccountManager am = new AccountManager();
        PersonalUser pu = (PersonalUser)am.GetUserById(User.Identity.Name, UserType.PersonalUser);
        txtName.Text = pu.Name;
        if (pu.Gender == 1)
            rbtn_boy.Checked = true;
        else
            rbtn_girl.Checked = true;
        txtCreateDate.Value = pu.Birthday.ToShortDateString();
        txtContactTel.Text = pu.TelephoneNumber;
        txtCellPhone.Text = pu.CellphoneNumber;
        txtHomePage.Text = pu.Homepage;
        for (int i = 0; i < ddlprovince.Items.Count; i++)
        {
            if (ddlprovince.Items[i].Text == pu.Province)
            {
                ddlprovince.SelectedIndex = i;
            }
        }
        txtEmail.Text = pu.MailAddress;
        txtAddress.Text = pu.Address;
        for (int j = 0; j < ddlCurrentStatu.Items.Count; j++)
        {
            if (ddlCurrentStatu.Items[j].Text == pu.CurrentStatu)
            {
                ddlCurrentStatu.SelectedIndex = j;
            }
        }
    }
    protected void ibtn_FinishEdit_Click(object sender, ImageClickEventArgs e)
    {
        if (txtName.Text == "" || txtCreateDate.Value == "" || txtCellPhone.Text == "" || txtEmail.Text == "" || txtAddress.Text == "")
        {
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "emptywarning", "<script type='txt/javascript'>alert('请确认带*号信息全部填写！');</script>");
        }
        else
        {
            AccountManager am = new AccountManager();
            PersonalUser pu = (PersonalUser)am.GetUserById(User.Identity.Name, UserType.PersonalUser);
            pu.Name = txtName.Text;
            if (rbtn_boy.Checked)
                pu.Gender = 1;
            else
                pu.Gender = 0;
            pu.Birthday = Convert.ToDateTime(txtCreateDate.Value);
            pu.TelephoneNumber = txtContactTel.Text;
            pu.CellphoneNumber = txtCellPhone.Text;
            pu.Homepage = txtHomePage.Text;
            pu.Province = ddlprovince.Items[ddlprovince.SelectedIndex].Text;
            pu.MailAddress = txtEmail.Text;
            pu.Address = txtAddress.Text;
            pu.CurrentStatu = ddlCurrentStatu.Items[ddlCurrentStatu.SelectedIndex].Text;
            if (am.UpdateUser(pu))
            {
                Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "added", "<script type='text/javascript'>alert('学生基本信息修改成功！');</script>");
                return;
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "failed", "<script type='text/javascript'>alert('学生基本信息修改未成功！');</script>");
                return;
            }
        }
    }
}
